import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2023-12-03
 * Time:10:13
 */
public class InsertSort {
    public static void main(String[] args) {
        int[] arr = {1,4,2,6,8,9,7,5,3,0};
        Sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void Sort(int[] arr) {
        for(int i = 1;i<arr.length;i++) {
            int j = i - 1;
            int start = arr[i];
            while (j >= 0) {
                if(arr[j] > start) {
                    arr[j + 1] = arr[j];
                    j--;
                } else {
                    break;
                }
            }
            arr[j+1] = start;
        }
    }
}
